<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">领取时间：</label>
                                    <div class="layui-input-inline">
                                        <input name="createTime" id="pTime" class="layui-input" type="text"
                                               placeholder="选择时间" autocomplete="off" readonly/>
                                    </div>
                                    <input name="startTime" id="startTime" type="hidden"/>
                                    <input name="endTime" id="endTime" type="hidden"/>
                                </div>
                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">物料名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuName" class="layui-input" type="text" placeholder="请输入物料名称" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <select name="skuCode" lay-filter="skuCode" lay-search lay-verify="">
                                            <option value="">请选物料编号</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">规格码：</label>
                                    <div class="layui-input-inline">
                                        <input name="oldSpecCode" class="layui-input" type="text" placeholder="请输入规格码" autocomplete="off"/>
                                    </div>
                                </div>-->
                                <div class="layui-inline">
                                    <label class="layui-form-label">工单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="workOrderCode" class="layui-input" type="text" placeholder="请输入工单编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">领用订单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="code" class="layui-input" type="text" placeholder="请输入领用订单编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <!--业务类型:cellCabOut(1,售刀柜领取);cellCabOutByOldNew(2,售刀柜领取(以旧换新))-->
                                <div class="layui-inline">
                                    <label class="layui-form-label">业务类型：</label>
                                    <div class="layui-input-inline">
                                        <select name="businessType" lay-filter="businessType" lay-search lay-verify="">
                                            <option value="">请选业务类型</option>
                                            <option value="cellCabOut">售刀柜领新</option>
                                            <option value="outByCabSpace">存刀柜领新</option>
                                            <option value="cellCabOutByOldNew">售刀柜领取(以旧换新)</option>
                                            <!--<option value="outByCabSpace">格子柜领新(以旧换新)</option>-->
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">部门：</label>
                                    <div class="layui-input-inline">
                                        <select name="departmentId" lay-filter="departmentId" lay-search lay-verify="">
                                            <option value="">请选部门</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">岗位角色：</label>
                                    <div class="layui-input-inline">
                                        <select name="roleId" lay-filter="roleId" lay-search lay-verify="">
                                            <option value="">请选岗位角色</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">操作人：</label>
                                    <div class="layui-input-inline">
                                        <select id="creatorId" name="creatorId" lay-filter="creatorId" lay-search
                                                lay-verify="">
                                            <option value="">请选操作人</option>
                                        </select>
                                    </div>
                                </div>
                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">柜子编号：</label>
                                    <div class="layui-input-inline">
                                        <select name="cabCode" lay-filter="cabCode" lay-search lay-verify="">
                                            <option value="">请选柜子</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">品牌：</label>
                                    <div class="layui-input-inline">
                                        <select name="brandId" lay-filter="brandId" lay-search lay-verify="">
                                            <option value="">请选品牌</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">分类：</label>
                                    <div class="layui-input-inline">
                                        <select name="categoryId" lay-filter="categoryId" lay-search lay-verify="">
                                            <option value="">请选分类</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">包装规格：</label>
                                    <div class="layui-input-inline">
                                        <select name="packId" lay-filter="packId" lay-search lay-verify="">
                                            <option value="">请选包装规格</option>
                                        </select>
                                    </div>
                                </div>-->
                                <div class="layui-inline">
                                    <label class="layui-form-label">机台：</label>
                                    <div class="layui-input-inline">
                                        <select name="deviceCode4Query" lay-filter="deviceCode" lay-search
                                                lay-verify="">
                                            <option value="">请选择机台</option>
                                        </select>
                                    </div>
                                </div>

                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt" style="height: 20px">
                            <!--<button id="cellInventoryOutExport" class="layui-btn icon-btn color-green">导出
                            </button>-->
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="storageInventoryInoutTable" lay-filter="storageInventoryInoutTable"></table>
        </div>
    </div>
</div>

<style>
    .layui-table-body .layui-none{
        background-color: #fff;
    }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="storageInventoryInoutTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <!--
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    -->
</script>

<!-- 表格操作列 -->
<script type="text/html" id="inoutDetailTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
</script>


<!-- 表单弹窗 -->
<script type="text/html" id="storageInventoryInoutForm">
    <form lay-filter="storageInventoryInoutForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">创建者</label>
            <div class="layui-input-block">
                <input name="creator" placeholder="请输入创建者" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改者</label>
            <div class="layui-input-block">
                <input name="modifier" placeholder="请输入修改者" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人</label>
            <div class="layui-input-block">
                <input name="creatorName" placeholder="请输入创建人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改人</label>
            <div class="layui-input-block">
                <input name="modifierName" placeholder="请输入修改人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">存刀任务编号</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入存刀任务编号" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">no</label>
            <div class="layui-input-block">
                <input name="no" placeholder="请输入no" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">day</label>
            <div class="layui-input-block">
                <input name="day" placeholder="请输入day" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">操作类型</label>
            <div class="layui-input-block">
                <select name="operationType">
                    <option value="in">存刀</option>
                    <option value="out">取刀</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">业务类型</label>
            <div class="layui-input-block">
                <select name="businessType">
                    <option value="temp">暂存</option>
                    <option value="repair">报修</option>
                    <option value="recycle">回收</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status">
                    <option value="created">已创建/待盘验</option>
                    <option value="checked">已盘验</option>
                    <option value="notified">已通知/回收中</option>
                    <option value="taked">平台已取货/已回收</option>
                    <option value="signed">已签收/已完成</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">盘验人id</label>
            <div class="layui-input-block">
                <input name="checkUserId" placeholder="请输入盘验人id" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">盘验人</label>
            <div class="layui-input-block">
                <input name="checkUserName" placeholder="请输入盘验人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">通知人</label>
            <div class="layui-input-block">
                <input name="notifyUserId" placeholder="请输入通知人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">通知人</label>
            <div class="layui-input-block">
                <input name="notifyUserName" placeholder="请输入通知人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">回收人id</label>
            <div class="layui-input-block">
                <input name="takeUserId" placeholder="请输入回收人id" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">回收人</label>
            <div class="layui-input-block">
                <input name="takeUserName" placeholder="请输入回收人" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="storageInventoryInoutFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<script type="text/html" id="detailTable">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->

                <!-- 表格 -->
                <table class="layui-table" id="inoutTable" lay-filter="inoutTable"></table>
                <br>
                <table class="layui-table" id="inoutDetailTable" lay-filter="inoutDetailTable"></table>
            </div>
        </div>
    </div>
</script>

<!--唯一码详情-->
<script type="text/html" id="labelCodeTable">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格 -->
                <table class="layui-table" id="outDetailTable" lay-filter="outDetailTable"></table>
                <br>
                <table class="layui-table" id="outLabelTable" lay-filter="outLabelTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;

        // 渲染表格
        var insTb = table.render({
            elem: '#storageInventoryInoutTable',
            url: config.base + 'enterprisecab/cabinet/admin/cellInventoryOutNew/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers',title: '序号',fixed: 'left'}
                , {field: 'code', sort: false, title: '领新订单编号', width: 160}
                , {field: 'businessTypeDesc', sort: false, title: '领新类型', width: 120}
                /*, {field: 'cabCode', sort: false, title: '所属柜子编号', width: 120}*/
                , {field: 'creatorName', sort: true, title: '领取人', width: 120}
                , {field: 'roleName', sort: false, title: '岗位'}
                , {field: 'departmentName', sort: false, title: '领取人部门'}
                , {field: 'productNum', sort: false, title: '产品数量'}
                , {field: 'quantity', sort: false, title: '包装数量'}
                , {field: 'quantityPack', sort: false, title: '基础单位数量', width: 120}
                , {field: 'total', sort: false, title: '总货值'}
                , {field: 'workOrderCode', sort: false, title: '工单'}
                , {field: 'deviceCode', sort: false, title: '机台'}
                , {field: 'deviceDepartmentName', sort: false, title: '机台部门'}
                , {
                    field: 'remainingTime', title: '刀具寿命', templet: function (d) {
                        if (d.lifeUnitDesc == '') {
                            return '不计寿命';
                        }
                        return d.remainingTime + '|' + d.settingTime;
                    }
                }
                , {field: 'createTime', sort: true, title: '领取时间', width: 160}
                , {align: 'center', fixed: 'right', toolbar: '#storageInventoryInoutTableBar', title: '操作', width: 80}
            ]],
        });

        // 工具条点击事件
        table.on('tool(storageInventoryInoutTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event == 'detail') {
                showDetailModel(data)
            }
        });

        //监听排序
        table.on('sort(storageInventoryInoutTable)', function (obj) {
            table.reload('storageInventoryInoutTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });
        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for(let key in field){
                field[key] = ''
            }
            insTb.reload({where: field,page: {curr: 1}},'data');
            selectManager(undefined, '#creatorId', '操作人');
        });

        // 合并生成订单
        $('#generateOrder').click(function () {
            let data = table.checkStatus('storageInventoryInoutTable').data, dataId = [];
            if (data.length === 0) {
                layer.msg('请选择需要合并生成订单的数据');
                return false
            }
            data.forEach(item => {
                dataId.push(item.id)
            });


            admin.req('enterprisecab/cabinet/admin/cellInventoryOut/createBill?ids=' + dataId.toString(), {}, res => {
                if (res.code === 200) {
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload('storageInventoryInoutTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'get')
        });

        // 获取部门
        admin.req('user/admin/department/list', {limit: 999}, function (res) {

            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择部门</option>';
                for (var k = 0; k < res.data.length; k++) {
                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='departmentId']").html(optionHtml);
                form.render('select');

            } else {
                layer.msg('获取部门失败', {icon: 2, time: 1000});
            }
        }, 'GET');

        admin.req('user/admin/role/list', {limit: 999}, function (res) {

            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择岗位角色</option>';
                for (var k = 0; k < res.data.length; k++) {
                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='roleId']").html(optionHtml);
                form.render('select');

            } else {
                layer.msg('获取岗位失败', {icon: 2, time: 1000});
            }
        }, 'GET');

        var selectManager = function (departmentId, elementId, optionDesc) {
            //获取责任人erpDepartmentId
            admin.req('user/admin/user/list', {departmentId: departmentId, limit: 999}, function (res) {
                if (200 == res.code) {
                    var optionHtml = '<option value=""> 请选择' + optionDesc + '</option>';
                    for (var k = 0; k < res.data.length; k++) {
                        optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].nickname + '|' + res.data[k].username + '</option>';
                    }
                    $(elementId).html(optionHtml);
                    form.render('select');


                } else {
                    layer.msg('获取责任人失败', {icon: 2, time: 1000});
                }
            }, 'GET');
        }
        selectManager(undefined, '#creatorId', '操作人');

        form.on('select(departmentId)', function (data) {
            selectManager(data.value, '#creatorId', '操作人');
        })

        admin.req('enterprisecab/cabinet/admin/cabinet/list', {
            limit: 999,
            cabinetNature: 'sale',
            cabinetType: 'spring'
        }, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择柜子</option>';
                for (var k = 0; k < res.data.length; k++) {
                    var nameCode = '';
                    if (res.data[k].cabName) {
                        nameCode = res.data[k].cabName + '|' + res.data[k].code;
                    } else {
                        nameCode = res.data[k].code;
                    }
                    optionHtml += '<option value="' + res.data[k].code + '">' + nameCode + '</option>';
                }
                $("select[name='cabCode']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        admin.req('enterprisecab/cabinet/admin/cabinet/list', {
            limit: 999,
            cabinetNature: 'sale',
            cabinetType: 'spring'
        }, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择柜子</option>';
                for (var k = 0; k < res.data.length; k++) {
                    var nameCode = '';
                    if (res.data[k].cabName) {
                        nameCode = res.data[k].cabName + '|' + res.data[k].code;
                    } else {
                        nameCode = res.data[k].code;
                    }
                    optionHtml += '<option value="' + res.data[k].code + '">' + nameCode + '</option>';
                }
                $("select[name='cabCode']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        admin.req('enterprise/product/admin/productBrand/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择品牌</option>';
                for (var k = 0; k < res.data.length; k++) {

                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='brandId']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');


        admin.req('enterprise/product/admin/productCategory/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择分类</option>';
                for (var k = 0; k < res.data.length; k++) {

                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='categoryId']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');


        admin.req('enterprise/product/admin/productPack/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择包装规格</option>';
                for (var k = 0; k < res.data.length; k++) {

                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='packId']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');


        admin.req('enterprise/product/admin/product/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择物料名称</option>';
                for (var k = 0; k < res.data.length; k++) {

                    optionHtml += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                }
                $("select[name='productId']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择物料编号</option>';
                for (var k = 0; k < res.data.length; k++) {
                    var nameCode = '';
                    if (res.data[k].productName) {
                        nameCode = res.data[k].productName + '|' + res.data[k].skuCode;
                    } else {
                        nameCode = res.data[k].skuCode;
                    }
                    optionHtml += '<option value="' + res.data[k].skuCode + '">' + nameCode + '</option>';
                }
                $("select[name='skuCode']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        /*admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择物料编号</option>';
                for (var k = 0; k < res.data.length; k++) {
                    var nameCode = '';
                    if (res.data[k].productName) {
                        nameCode = res.data[k].productName + '|' + res.data[k].oldSpecCode;
                    } else {
                        nameCode = res.data[k].oldSpecCode;
                    }
                    optionHtml += '<option value="' + res.data[k].oldSpecCode + '">' + nameCode + '</option>';
                }
                $("select[name='oldSpecCode']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');*/

        admin.req('enterprise/device/admin/device/list', {limit: 999}, function (res) {
            if (200 == res.code) {
                var optionHtml = '<option value=""> 请选择机台</option>';
                for (var k = 0; k < res.data.length; k++) {
                    var nameCode = '';
                    if (res.data[k].name) {
                        nameCode = res.data[k].name + '|' + res.data[k].deviceCode;
                    } else {
                        nameCode = res.data[k].deviceCode;
                    }
                    optionHtml += '<option value="' + res.data[k].deviceCode + '">' + nameCode + '</option>';
                }
                $("select[name='deviceCode4Query']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        form.render('select');

        // 添加按钮点击事件
        $('#storageInventoryInoutBtnAdd').click(function () {
            showEditModel();
        });

        function getReceiveData(data) {
            var insTb = table.render({
                elem: '#inoutTable',
                // url: config.base + 'enterprisecab/cabinet/admin/cellInventoryInout/list?id=' + data.id + '&skuCode4Detail=' + data.skuCode,
                data: [data],
                page: false,
                cellMinWidth: 100,
                cols: [[
                    {field: 'code', title: '领新订单编号', width: 160}
                    , {field: 'businessTypeDesc', title: '领新类型', width: 120}
                    /*, {field: 'cabCode', title: '所属柜子编号', width: 120}*/
                    , {field: 'creatorName', title: '领取人', width: 120}
                    , {field: 'roleName', title: '岗位'}
                    , {field: 'departmentName', title: '领取人部门'}
                    , {field: 'productNum', title: '产品数量'}
                    , {field: 'total', title: '总货值'}
                    , {field: 'workOrderCode', title: '工单'}
                    , {field: 'deviceCode', title: '机台'}
                    , {field: 'deviceDepartmentName', title: '机台部门'}
                    , {
                        field: 'remainingTime', title: '刀具寿命', templet: function (d) {
                            if (d.lifeUnitDesc == '') {
                                return '不计寿命';
                            }
                            return d.remainingTime + '|' + d.settingTime;
                        }
                    }
                    , {field: 'createTime', title: '领取时间', width: 160}
                ]]
            });
        }

        function getReceiveDetail(data) {
            var insTb = table.render({
                elem: '#inoutDetailTable',
                // url: config.base + 'enterprisecab/cabinet/admin/cellInventoryInoutDetail/list?inoutId='+data.id+'&skuCode4detail='+data.skuCode,
                url: config.base + 'enterprisecab/cabinet/admin/cellInventoryInoutDetail/list?inoutId=' + data.id,
                page: true,
                cellMinWidth: 100,
                cols: [[
                    {type: 'numbers'}
                    , {
                        field: 'skuPic', title: '物料图片', templet: function (d) {
                            if (d.skuPic) {
                                return '<img src="' + d.skuPic + '" style="height: 20px;"/>';
                            }
                            return '<img src="assets/images/default-icon.png"/>';
                        }
                    }
                    , {field: 'skuCode', title: '物料编号'}
                    , {field: 'skuName', title: '物料名称'}
                    , {field: 'skuSpecOld', title: '规格码'}
                    , {field: 'productBrandName', title: '品牌'}
                    , {field: 'cabCode', title: '柜子编号'}
                    , {field: 'spaceCode', title: '货道编号'}
                    , {field: 'packName', title: '包装规格'}
                    , {field: 'quantity', title: '数量(包装计)', width: 120, templet: function (d) {
                            return d.quantity < 0 ? d.quantity * -1 : d.quantity
                        }}
                    , {field: 'unitName', title: '包装单位'}
                    , {field: 'quantityPack', title: '数量(基础单位计)', width: 140, templet: function (d) {
                            return d.quantityPack < 0 ? d.quantityPack * -1 : d.quantityPack
                        }}
                    , {field: 'basicsUnitName', title: '基础单位'}
                    , {field: 'price', title: '包装单价'}
                    , {field: 'basePrice', title: '基础单价'}
                    , {field: 'total', title: '总价'}
                    , {align: 'center', fixed: 'right', toolbar: '#inoutDetailTableBar', title: '操作', width: 80}
                ]]
            });

            // 工具条点击事件
            table.on('tool(inoutDetailTable)', function (obj) {
                var data = obj.data;
                if (obj.event == 'detail') {
                    showDetailModel(data)
                }
            });

            function showDetailModel(data) {
                admin.open({
                    type: 1,
                    area: '80%',
                    offset: '65px',
                    title: '唯一码详情',
                    content: $('#labelCodeTable').html(),
                    success: function () {

                        var insTb = table.render({
                            elem: '#outDetailTable',
                            data: [data],
                            page: false,
                            cellMinWidth: 100,
                            cols: [[
                                {
                                    field: 'skuPic', title: '物料图片', templet: function (d) {
                                        if (d.skuPic) {
                                            return '<img src="' + d.skuPic + '" style="height: 20px;"/>';
                                        }
                                        return '<img src="assets/images/default-icon.png"/>';
                                    }
                                }
                                , {field: 'skuCode', title: '物料编号'}
                                , {field: 'skuName', title: '物料名称'}
                                , {field: 'skuSpecOld', title: '规格码'}
                                , {field: 'productBrandName', title: '品牌'}
                                , {field: 'cabCode', title: '柜子编号'}
                                , {field: 'spaceCode', title: '货道编号'}
                                , {field: 'packName', title: '包装规格'}
                                , {field: 'quantity', title: '数量(包装计)', width: 120, templet: function (d) {
                                        return d.quantity < 0 ? d.quantity * -1 : d.quantity
                                    }}
                                , {field: 'unitName', title: '包装单位'}
                                , {field: 'quantityPack', title: '数量(基础单位计)', width: 140, templet: function (d) {
                                        return d.quantityPack < 0 ? d.quantityPack * -1 : d.quantityPack
                                    }}
                                , {field: 'basicsUnitName', title: '基础单位'}
                                , {field: 'price', title: '包装单价'}
                                , {field: 'basePrice', title: '基础单价'}
                                , {field: 'total', title: '总价'}
                            ]]
                        });

                        var outLabelTb = table.render({
                            elem: '#outLabelTable',
                            url: config.base + 'enterprisecab/cabinet/admin/cellInventoryOutLabel/list?inoutDetailId=' + data.id,
                            page: true,
                            cellMinWidth: 100,
                            cols: [[
                                {type: 'numbers'}
                                , {field: 'labelCode', title: '物料唯一码'}
                                , {field: 'parentCode', title: '包装码'}
                            ]]
                        });

                    }
                })
            }

        }

        function showDetailModel(data) {
            admin.open({
                type: 1,
                area: '80%',
                offset: '65px',
                title: '详情',
                content: $('#detailTable').html(),
                success: function () {
                    getReceiveData(data)
                    getReceiveDetail(data);
                }
            })
        }

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '880px',
                offset: '65px',
                title: data ? '修改暂存柜存刀/取刀;存/取报修/回收刀' : '添加暂存柜存刀/取刀;存/取报修/回收刀',
                content: $('#storageInventoryInoutForm').html(),
                success: function () {
                    if (data) {
                        var option = $("form select[name='operationType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.operationType == item.text) {
                                data.operationType = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='businessType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.businessType == item.text) {
                                data.businessType = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.status == item.text) {
                                data.status = item.value;
                            }
                        });
                    }

                    form.val('storageInventoryInoutForm', data);
                    // 表单提交事件
                    form.on('submit(storageInventoryInoutFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprisecab/cabinet/admin/storageInventoryInout/update' : 'enterprisecab/cabinet/admin/storageInventoryInout/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('storageInventoryInoutTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabinet/admin/storageInventoryInout/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    let dateValue = value.split(" - ");
                    $("#startTime").val(dateValue[0] + " 00:00:00");
                    $("#endTime").val(dateValue[1] + " 23:59:59");
                } else {
                    $("#startTime").val("");
                    $("#endTime").val("");
                }
            }
        });

        // 导出领用订单
        $('#cellInventoryOutExport').click(function () {
            var sTime = $('#startTime').val();
            var eTime = $('#endTime').val();

            if (sTime == "" && eTime == "") {
                layer.msg('请先选择领取时间！')
            } else {

                location.href = config.base + 'enterprisecab/cabinet/admin/cellInventoryOut/export?type=1&startCreateTime=' + sTime + '&endCreateTime=' + eTime;
            }
        });

    });
</script>